package hihocode;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class Offer20Probem1 {

	HashSet<Integer> parent = new HashSet<>();

	private static final int MAX = 1002;
	int[] parents = new int[MAX];
	int[][] edges = new int[MAX][2];

	public static void main(String[] args) {
		Offer20Probem1 object = new Offer20Probem1();
		object.getRes();
	}

	public void getRes() {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			Arrays.fill(parents, 0);
			parent.clear();
			int n = scanner.nextInt();
			int root = scanner.nextInt();
			parent.add(root);
			// 一共有n-1行
			for (int i = 1; i < n; i++) {
				edges[i][0] = scanner.nextInt();
				edges[i][1] = scanner.nextInt();
			}
			while (parent.size() < n) {
				for (int i = 1; i < n; i++) {
					int firstIndex = edges[i][0];
					int secondIndex = edges[i][1];
					boolean isFirst = parent.contains(firstIndex);
					boolean isSecond = parent.contains(secondIndex);
					if (isFirst ^ isSecond) {
						if (isFirst) {
							parents[secondIndex] = firstIndex;
							parent.add(secondIndex);
						} else {
							parents[firstIndex] = secondIndex;
							parent.add(firstIndex);
						}
					}
				}
			}
			for(int i = 1; i < n; i++){
				System.out.print(parents[i] + " ");
			}
			System.out.println(parents[n]);
		}
		scanner.close();
	}
}
